import javax.microedition.lcdui.Graphics;

public class ap extends ba
{

    public int c;
    private ba a[];

    public ap(o o1, int i, int j)
    {
        super(o1, i, j);
        a = new ba[8];
        c = 0;
    }

    public final int g_()
    {
        return c;
    }

    public final ba a(int i)
    {
        if(0 <= i && i < c)
            return a[i];
        else
            return null;
    }

    private void c(int i)
    {
        if(i > a.length)
        {
            ba aba[] = new ba[i + 8];
            System.arraycopy(a, 0, aba, 0, c);
            a = aba;
        }
    }

    public final void d()
    {
        z();
        int i = c;
        c = 0;
        ba aba[] = a;
        for(int j = 0; j < i; j++)
        {
            a(aba[j], null);
            aba[j] = null;
        }

    }

    public final void b(int i, ba ba1)
    {
        int j = c;
        if(i == j)
        {
            b(ba1);
            return;
        }
        if(0 <= i && i < j)
        {
            z();
            c(j + 1);
            ba1.H = this;
            for(int k = j; k > i; k--)
                a[k] = a[k - 1];

            a[i] = ba1;
            c++;
        }
    }

    public final void a(int i, ba ba1)
    {
        if(i == c)
        {
            b(ba1);
            return;
        }
        if(0 <= i && i < c)
        {
            z();
            ba aba[] = a;
            ba1.H = this;
            a(aba[i], ba1);
            aba[i] = ba1;
        }
    }

    public final ap b(ba ba1)
    {
        z();
        c(c + 1);
        ba1.H = this;
        a[c++] = ba1;
        return this;
    }

    public final void b(int i)
    {
        if(0 <= i && i < c)
        {
            z();
            int j = c - 1;
            ba aba[] = a;
            a(aba[i], null);
            if(i < j)
            {
                for(int k = i; k < j; k++)
                    aba[k] = aba[k + 1];

            }
            aba[--c] = null;
        }
    }

    public final void c(ba ba1)
    {
        int i;
        if((i = d(ba1)) >= 0)
            b(i);
    }

    public final int g()
    {
        return a(false, 0);
    }

    private static int a(ba ba1, int i, int j)
    {
        if(ba1.v())
            return bh.b(ba1.u(), i);
        int k;
        if((k = i - j) <= 0)
            k = i;
        if((ba1.L & 0x80) != 0)
            return k;
        int l = bh.b(ba1.u(), i);
        if((ba1.L & 0x100) != 0 && l > k)
            return k;
        else
            return l;
    }

    public final int g(int i)
    {
        return a(true, i);
    }

    private int a(boolean flag, int i)
    {
        int j = 0;
        int k = 0;
        int l = 0;
        int i1 = 0;
        int j1 = c;
        for(int k1 = 0; k1 < j1; k1++)
        {
            ba ba1;
            if(!(ba1 = a(k1)).C())
                continue;
            int l1 = a(ba1, i, k);
            int i2;
            if((i2 = ba1.j(l1)) < 0)
                throw new RuntimeException("Ambiguous: Flow height=0 and child height<0");
            if(ba1.E() && k + l1 > i)
            {
                j += l;
                k = 0;
                l = 0;
            }
            l = Math.max(l, i2);
            k += l1;
            i1 = Math.max(i1, k);
            if(ba1.D())
            {
                j += l;
                k = 0;
                l = 0;
            }
        }

        if(flag)
            return j + l;
        else
            return i1;
    }

    public int a(int i, int j, int k, int l)
    {
        int i1 = c;
        int j1 = 0;
        int k1 = 0;
        int l1 = super.I.v;
        int i2 = super.I.w;
        int j2 = 0;
        int k2 = 0;
        int l2 = 0;
        for(int j3 = 0; j3 < i1; j3++)
        {
            ba ba1;
            if((ba1 = a(j3)).C())
            {
                boolean flag2 = true;
                int i4 = a(ba1, k, k2);
                int k4 = 0;
                if(ba1.w() || (ba1 instanceof ap))
                {
                    k4 = bh.b(ba1.j(i4), l);
                    flag2 = false;
                }
                if(ba1.E() && k2 + i4 > k)
                {
                    l2 += j2 + i2;
                    k2 = 0;
                    j2 = 0;
                }
                ba1.b(i + k2, j + l2, i4, k4);
                if(flag2)
                    k4 = ba1.K.g;
                j2 = Math.max(j2, k4);
                k2 += i4 + l1;
                j1 = Math.max(j1, k2 - l1);
                if(ba1.D())
                {
                    l2 += j2 + i2;
                    k2 = 0;
                    j2 = 0;
                }
            } else
            {
                ba1.K.b();
            }
            k1 = Math.max(k1, (l2 + j2) - i2);
        }

        boolean flag = !v() && (super.H instanceof ah);
        boolean flag1 = !w() && (super.H instanceof ah);
        if(super.I.e != 0 || super.I.v != 0)
        {
            int i3 = flag1 ? 0 : bh.b(super.I.e, l, k1);
            short word0 = -1;
            int k3 = 0;
            int l3 = 0;
            int j4 = 0;
            int l4 = flag ? j1 : k;
            for(int i5 = 0; i5 < i1; i5++)
            {
                ba ba2;
                if(!(ba2 = a(i5)).C())
                    continue;
                short word1 = ba2.K.e;
                if(word0 != word1)
                {
                    if(i5 > k3)
                        a(k3, i5, l4, l3 - l1, j4, i3);
                    l3 = 0;
                    j4 = 0;
                    k3 = i5;
                    word0 = word1;
                }
                l3 += ba2.K.f + l1;
                j4 = Math.max(j4, ba2.K.g);
            }

            if(k3 < i1)
                a(k3, i1, l4, l3 - l1, j4, i3);
        }
        super.K.f = (short)((flag ? j1 : k) + super.I.g());
        super.K.g = (short)((flag1 ? k1 : l) + super.I.h());
        if((super.H instanceof ah) && ce.f == 1)
            a();
        return k1;
    }

    private void a(int i, int j, int k, int l, int i1, int j1)
    {
        if(k > 0 && i1 > 0)
        {
            int k1 = 0;
            if(l < k)
                k1 = bh.a(super.I.e, k, l);
            for(int l1 = i; l1 < j; l1++)
            {
                ba ba1 = a(l1);
                b(ba1, k1, j1 + bh.b(super.I.x, i1, ba1.K.g));
            }

        }
    }

    private void b(ba ba1, int i, int j)
    {
        if(ba1.C())
        {
            bk bk1;
            (bk1 = ba1.K).d += i;
            bk1.e += j;
            if(!(ba1 instanceof ah))
            {
                int k = 0;
                for(int l = ba1.g_(); k < l; k++)
                    b(ba1.a(k), i, j);

            }
        }
    }

    public void a()
    {
        int i = c;
        short word0 = 0;
        boolean flag = false;
        for(int j = 0; j < i; j++)
        {
            ba ba1;
            if(!(ba1 = a(j)).C())
                continue;
            if(super.N == 0 && !flag)
            {
                word0 = ba1.K.d;
                flag = true;
            }
            ba1.m(word0);
            if(ba1.D())
                flag = false;
        }

    }

    public final void a(Graphics g1, bh bh1, o o1, int i, int j)
    {
        int k = super.K.d + o1.c();
        int l = super.K.e + o1.e();
        int i1 = g1.getTranslateX();
        int j1 = g1.getTranslateY();
        int k1 = g1.getClipWidth();
        int l1 = g1.getClipHeight();
        int i2 = 0;
        for(int j2 = c; i2 < j2; i2++)
        {
            ba ba1;
            if(!(ba1 = a(i2)).C())
                continue;
            bk bk1 = ba1.K;
            g1.translate(((bk1.d - k) + i1) - g1.getTranslateX(), ((bk1.e - l) + j1) - g1.getTranslateY());
            int k2 = g1.getClipX();
            int l2;
            if((l2 = g1.getClipY()) <= bk1.g && k2 <= bk1.f && l2 + l1 >= 0 && k2 + k1 >= 0)
                bh.a(g1, bh1, ba1);
        }

    }
}